﻿package export.mapPrefab.trap
{
	import base.BaseAddEffect;
	import base.BaseHero;
	
	import com.dusk.tool.HitTest;
	
	import config.Config;
	
	import flash.display.MovieClip;
	import flash.geom.*;
	
	public class IceThron extends MovieClip
	{
		
		public function IceThron()
		{
			super();
			this.addFrameScript(0, this.frame1);
			this.gc = Config.getIns();
		}
		
		public var isIceThron:MovieClip;
		private var attackId:uint = 0;
		private var gc:Config;
		private var intervalCount:uint = 0;
		
		public function step():void
		{
			var _loc1_:* = null;
			var _loc2_:Boolean = false;
			if (this.intervalCount == 0)
			{
				
				this.intervalCount = Number(this.gc.frameClips) * 2;
			}
			if (this.intervalCount >= 0)
			{
				--this.intervalCount;
			}
			if (this.y < 100)
			{
				if (this.currentFrame == 1)
				{
					_loc2_ = false;
					if (this.gc.hero1)
					{
						if (Math.abs(this.x - Number(this.gc.hero1.x)) <= 200)
						{
							_loc2_ = true;
						}
					}
					if (!_loc2_)
					{
						if (this.gc.hero2)
						{
							if (Math.abs(this.x - Number(this.gc.hero2.x)) <= 200)
							{
								_loc2_ = true;
							}
						}
					}
					if (_loc2_)
					{
						this.gotoAndPlay(2);
					}
				}
			}
			for each (_loc1_ in this.gc.team.getHeroArray())
			{
				if (_loc1_.beAttackIdArray.indexOf(this.getAttackId()) == -1)
				{
					if (!_loc1_.isInvincible())
					{
						if (HitTest.complexHitTestObject(this, _loc1_.colipse))
						{
							_loc1_.reduceHp(20 + Math.ceil(Math.random() * 10), true);
							if (Math.random() < 0.25)
							{
								BaseHero(_loc1_).addCurAddEffect([{
									"name": BaseAddEffect.ICE,
									"time": gc.frameClips * 1.5
								}]);
							}
							if (_loc1_.getBBDC().getDirect() == 0)
							{
								_loc1_.setAttackBack(new Point(10, 0));
							}
							else
							{
								_loc1_.setAttackBack(new Point(-10, 0));
							}
							_loc1_.beAttackIdArray.push(this.getAttackId());
							_loc1_.beAttackDoing();
						}
					}
				}
			}
		}
		
		private function frame1():void
		{
			stop();
		}
		
		private function getAttackId():String
		{
			return this.name + this.attackId;
		}
		
		private function newAttackId():void
		{
			++this.attackId;
		}
	}
}
